package com.kwan.xframe.mvvm.binding;

import android.util.SparseArray;

import com.kwan.xframe.view_model.BaseViewModel;

import androidx.annotation.NonNull;

/**
 * @author kwan
 * @date 2023/2/16 13:47
 */
public class DataBindingConfig {


	private final int layout;

	private final int vmVariableId;

	private final BaseViewModel stateViewModel;

	private SparseArray<BaseViewModel> bindingParams;

	public DataBindingConfig(@NonNull Integer layout,
							 @NonNull Integer vmVariableId,
							 BaseViewModel stateViewModel) {
		this.layout = layout;
		this.vmVariableId = vmVariableId;
		this.stateViewModel = stateViewModel;
	}

	public DataBindingConfig(@NonNull Integer layout) {
		this.layout = layout;
		this.vmVariableId = -1;
		this.stateViewModel = null;
	}

	public int getLayout() {
		return layout;
	}

	public int getVmVariableId() {
		return vmVariableId;
	}

	public BaseViewModel getStateViewModel() {
		return stateViewModel;
	}

	public SparseArray<BaseViewModel> getBindingParams() {
		return bindingParams;
	}

	public DataBindingConfig addBindingParam(@NonNull Integer variableId,
											 @NonNull BaseViewModel viewModel) {

		if (bindingParams == null)
			bindingParams = new SparseArray<>();

		if (bindingParams.get(variableId) == null) {
			bindingParams.put(variableId, viewModel);
		}
		return this;
	}


}
